package com.qili.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.qili.base.controller.BaseController;
import com.qili.core.utils.DictTypes;
import com.qili.core.utils.DictUtil;
import com.qili.entity.base.BaseCompany;
import com.qili.entity.base.BaseDict;
import com.qili.entity.supervisor.ProjectContract;
import com.qili.entity.supervisor.ProjectUnitConstruction;
import com.qili.entity.supervisor.SupervisorFile;
import com.qili.entity.supervisor.SupervisorProjectForms;
import com.qili.entity.supervisor.dto.ProjectLeaderDTO;
import com.qili.entity.supervisor.dto.ProjectUnitConstructionDTO;
import com.qili.entity.supervisor.dto.SupervisorFileDTO;
import com.qili.entity.supervisor.dto.SupervisorProjectDTO;
import com.qili.entity.jc.JcProject;
import com.qili.entity.jc.JcProjectMilepost;
import com.qili.entity.jc.JcProjectStage;
import com.qili.entity.jc.dto.JcProjectDTO;
import com.qili.entity.jc.dto.JcProjectPayDTO;
import com.qili.service.SysUserService;
import com.qili.service.base.BaseCompanyOwnerService;
import com.qili.service.base.BaseCompanyService;
import com.qili.service.base.BaseDictService;
import com.qili.service.supervisor.*;
import com.qili.service.supplier.ProjectPlaceService;
import com.qili.service.sys.SysRegionService;
import com.qili.service.jc.JcProjectMilepostService;
import com.qili.service.jc.JcProjectPayService;
import com.qili.service.jc.JcProjectService;
import com.qili.service.jc.JcProjectStageService;
import com.qili.util.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import tk.mybatis.mapper.entity.Example;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhaoyongke
 * @date 2021/6/29
 * @description
 */
@Controller
@Slf4j
@RequestMapping("/jc/fileUpManager")
public class JcUploadFileController extends BaseController {

    @Autowired
    SupervisorFileService supervisorFileService;
    @Autowired
    SysUserService sysUserService;
    @Autowired
    BaseDictService baseDictService;
    @Autowired
    SysRegionService sysRegionService;
    @Autowired
    BaseCompanyOwnerService baseCompanyOwnerService;
    @Autowired
    JcProjectService jcProjectService;
    @Autowired
    ProjectContractService projectContractService;
    @Autowired
    ProjectLeaderService projectLeaderService;

    @Autowired
    JcProjectStageService jcProjectStageService;

    @Autowired
    JcProjectMilepostService jcProjectMilepostService;

    @Autowired
    JcProjectPayService jcProjectPayService;

    @Autowired
    ProjectPlaceService projectPlaceService;
    @Autowired
    ProjectUnitConstructionService projectUnitConstructionService;
    @Autowired
    BaseCompanyService baseCompanyService;
    @Autowired
    UploadUtil uploadUtil;
    @Autowired
    SupervisorProjectFormsService supervisorProjectFormsService;

    /**
    * @Author:zhaoyongke
    * @Description:  招标文件
    * @param model
    * @param request
    * @Date:10:49 2021/6/29
    */
    @GetMapping(value = "mapper")
    public String mapper(Model model, HttpServletRequest request) {
        String url=request.getParameter("url");
        String id = request.getParameter("id");// 项目id
        String spmid = request.getParameter("spmid");// 里程id
        String stageid = request.getParameter("stageid");// 里程id
        //查询项目
        JcProject supervisorProject = new JcProject();
        supervisorProject.setId(id);
        JcProject project = jcProjectService.selectByPrimaryKey(id);
        // 查询里程
        JcProjectMilepost milepost = new JcProjectMilepost();
        milepost.setId(spmid);
        milepost = jcProjectMilepostService.selectByPrimaryKey(milepost);
        // 各个文件状态
        String stepNum = milepost.getStepNum();
        if(StringUtil.isNotBlank(stepNum)){
            String[] split = stepNum.split(",");
            for (int i = 0; i <split.length ; i++) {
                String stepnum= split[i];
                request.setAttribute("fi_"+stepnum, stepnum);
            }

        }

        // 查询阶段
        JcProjectStage stage = new JcProjectStage();
        stage.setId(stageid);
        stage = jcProjectStageService.selectByPrimaryKey(stage);
        String milepostNo = milepost.getMilepostNo();

        BaseDict AoBaseDict = DictUtil.getDictByCode(DictTypes.PROJECT_MILEPOST_JC, milepostNo);
        String wjcode = AoBaseDict.getBadtLevel3();
        if(StringUtil.isNotBlank(wjcode)){
            String[] split = wjcode.split(",");
            for (int i = 0; i < split.length; i++) {
                String type=split[i];
                List<SupervisorFile> listjlzb=null;
                if("031".equals(type)){
                    //咨询付款申请 查询  需要过滤掉图片
                    Example e = new Example(SupervisorFile.class);
                    Example.Criteria c = e.createCriteria();
                    c.andEqualTo("projectId", id).andEqualTo("spmId", spmid).andEqualTo("type", type).andIsNull("parentId");
                    listjlzb = supervisorFileService.selectByExample(e);
                }else{
                    SupervisorFile supervisorFile = new SupervisorFile();
                    supervisorFile.setType(type);
                    supervisorFile.setProjectId(id);
                    supervisorFile.setSpmId(spmid);
                    listjlzb = supervisorFileService.select(supervisorFile);
                }
                if("012".equals(type) || "013".equals(type)|| "014".equals(type) || "015".equals(type)|| "017".equals(type) || "026".equals(type)   ||"022".equals(type)   || "033".equals(type)    || "034".equals(type)   || "035".equals(type)    || "036".equals(type) ){
                    getButFinishStatus(listjlzb, type, request);
                }
                request.setAttribute("listwj"+type, listjlzb);
            }

        }

        SupervisorProjectDTO pdto = new SupervisorProjectDTO();
        BeanUtils.copyProperties(project, pdto);
        pdto.setSpmId(spmid);
        request.setAttribute("pdto", pdto);
        request.setAttribute("lcdto", milepost);
        request.setAttribute("stagedto", stage);

        return "/jc/projectManager/"+url;
    }
    /**
     * @param filelist
     * @param wjcode
     * @param request
     * @Author:zhaoyongke
     * @Description:获取按钮状态
     * @Date:15:50 2020/12/23
     */
    public void getButFinishStatus(List<SupervisorFile> filelist, String wjcode, HttpServletRequest request) {
        // 判断流程是否进行完
        Boolean isxs = getLcStatus(filelist, wjcode, "");
        request.setAttribute("finish_status_" + wjcode, isxs);
    }

    /**
     * @param filelist
     * @param wjcode
     * @Author:zhaoyongke
     * @Description: 判断流程是否结束
     * @Date:14:55 2020/12/31
     */
    public Boolean getLcStatus(List<SupervisorFile> filelist, String wjcode, String type) {
        BaseDict dict = DictUtil.getDictByCode(DictTypes.WJJC, wjcode);
        String lcsl = dict.getBadtLevel3();
        Boolean isxs = true;
        if (StringUtil.isNotBlank(lcsl)) {
            // 流程都结束后才可以显示
            //流程状态0 内部未发起流程1 内部进行中 2 内部流程审核通过3内部流程审核不通过4外部流程进行中5外部流程审核通过（归档）6 外部流程审核不通过
            for (int i = 0; i < filelist.size(); i++) {
                SupervisorFile file = filelist.get(i);
                //流程状态
                String lcstatus = file.getLcStatus();
                // 3 包含外部流和内部流程 2 只包含外部流程   1 只包含内部流程
                if ("3".equals(lcsl) || "2".equals(lcsl)) {
                    if ("001".equals(type)) {

                        if (!"3".equals(lcstatus) && !"5".equals(lcstatus) && !"6".equals(lcstatus) && lcstatus != null && !"".equals(lcstatus)) {
                            // 流程进行 不能删除
                            isxs = false;
                            break;
                        }
                    } else {
                        if (!"5".equals(lcstatus)) {
                            // 流程未结束  不能点击完成按钮 按钮 隐藏
                            isxs = false;
//                            if("4".equals(lcstatus) ){
//                                //流程进行中,判断该操作人是不是项目的总监理工程师:
//                                String actor = CommonUtil.getUserId();
//                                String projectId = file.getProjectId();
//                                if(StringUtils.isNotBlank(projectId)){
//                                    SupervisorProject project = supervisorProjectService.selectByPrimaryKey(projectId);
//                                    if(null != project){
//                                        //项目的总监理工程师:
//                                        String supervisorEngineer = project.getSupervisorEngineer();
//                                        if(actor.equals(supervisorEngineer)){
//                                            isxs = true;
//                                        }
//                                    }
//                                }
//                            }
                            break;
                        }
                    }

                } else if ("1".equals(lcsl)) {
                    if ("001".equals(type)) {
                        if (!"2".equals(lcstatus) && !"3".equals(lcstatus) && lcstatus != null && !"".equals(lcstatus)) {
                            // 流程进行 不能删除
                            isxs = false;
                            break;
                        }
                    } else {
                        if (!"2".equals(lcstatus)) {
                            // 流程未结束  不能点击完成按钮 按钮 隐藏
                            isxs = false;
                            break;
                        }
                    }

                }

            }
        }
        return isxs;
    }


    /**
     * @param
     * @Author:zhaoyongke
     * @Description: 表单文件添加
     * @Date:9:29 2020/11/30
     */
    @GetMapping(value = "addForm")
    public String addForm(JcProjectDTO dto, HttpServletRequest request, Model model) throws Exception {
        String type = dto.getType();// 文件類型
        String spf_prjid = dto.getId();// 項目id
        String spf_staid = dto.getStageId();// 阶段id
        String spf_milid = dto.getSpmId();// 里程id
        String fbCode = dto.getFbCode();// 分包
        String pcId = dto.getFbId();// 分包Id
        String fileId = dto.getFileId();// 文件表id  个别form 添加是针对某个文档操作 需要知道具体是哪个文件 fileId
        String role = sysUserService.getUserRoleJc(spf_prjid);
        // 项目经理  授权签字人  检测工程师
        if ("xmjl".equals(role) || "sqqzr".equals(role)  || "jcgw".equals(role)) {
        } else {
            request.setAttribute("message", "没有权限操作");
            return "/error/lcerror";
        }
        //查询项目详情
        JcProjectDTO supervisorProjectdto = getSupervisorProjectDTO(spf_prjid);
        supervisorProjectdto.setFileId(fileId);
        // 获得文档流水号
        String orderCode = getFileOrderCode(spf_prjid, spf_staid, spf_milid, pcId, type);
        // 获取跳转路径
        String re_url = getUrl(type, model);
        //特殊处理
        doSomeSpecialSthing(model, type, spf_prjid, fbCode, supervisorProjectdto, orderCode);
        // 查询业主单位
        ProjectLeaderDTO leaderdto = new ProjectLeaderDTO();
        leaderdto.setSupervisorProjectId(spf_prjid);
        JcProjectPayDTO payDTO = new JcProjectPayDTO();
        payDTO.setSppPrjid(spf_prjid);
        List<JcProjectPayDTO> listpay = jcProjectPayService.selectSupervisorProjectPay(payDTO);
        List<ProjectLeaderDTO> listyz = projectLeaderService.selectProjectLeaderList(leaderdto);
        //解析文件数据
        parsingFileDataToList(model, type, fileId, spf_prjid, pcId);
        model.addAttribute("ind", Integer.valueOf(orderCode));
        model.addAttribute("pdto", supervisorProjectdto);
        model.addAttribute("listpay", listpay);
        model.addAttribute("listpayCount", listpay.size());
        model.addAttribute("spf_prjid", spf_prjid);
        model.addAttribute("spf_staid", spf_staid);
        model.addAttribute("spf_milid", spf_milid);
        model.addAttribute("spfFilecode", type);// 文件类型编号
        model.addAttribute("fbCode", fbCode);// 分包编号
        model.addAttribute("pcId", pcId);// 分包编号
        model.addAttribute("fileId", fileId);// 文件表id
        model.addAttribute("listyz", listyz);// 业主单位
        return re_url;
    }
    /**
     * @param fbId
     * @Author:zhaoyongke
     * @Description: 检查分包有没有承建单位 没有承建单位不能上传文件
     * @Date:16:18 2021/1/21
     */
    public Boolean checkFbCj(String fbId, String projectId) {
        Boolean isCheck = true;
        ProjectContract contract = projectContractService.selectByPrimaryKey(fbId);
        String code = contract.getCode();
        if (StringUtil.isNotBlank(code)) {
            //查询承建单位
            ProjectUnitConstruction unitConstruction = new ProjectUnitConstruction();
            unitConstruction.setSupervisorProjectId(projectId);
            unitConstruction.setConstructionSubContractNumber(code);
            int count = projectUnitConstructionService.selectCount(unitConstruction);
            if (count == 0) {
                isCheck = false;
            }
        }
        return isCheck;
    }
    /**
     * @param spf_prjid
     * @Description:获取SupervisorProject
     * @Author:Zhangshuo
     * @Date:11:20 2020-12-19
     */
    private JcProjectDTO getSupervisorProjectDTO(String spf_prjid) {
        JcProjectDTO supervisorProjectdto = new JcProjectDTO();
        //查询项目
        supervisorProjectdto.setId(spf_prjid);
        List<JcProjectDTO> projectlist = jcProjectService.selectSupervisorProject(supervisorProjectdto);
        if (projectlist.size() > 0) {
            supervisorProjectdto = projectlist.get(0);
        }
        return supervisorProjectdto;
    }
    /**
     * @param spf_prjid 项目ID
     * @param spf_milid 里程ID
     * @param fbid      分包ID
     * @param psType    文件类型
     * @Author:Zhangshuo
     * @Description:
     * @Date:12:25 2020/12/4
     */
    public String getFileOrderCode(String spf_prjid, String spf_staid, String spf_milid, String fbid, String psType) {
        SupervisorFile AoSupervisorFile = new SupervisorFile();
        AoSupervisorFile.setProjectId(spf_prjid);
        AoSupervisorFile.setStageId(spf_staid);
        AoSupervisorFile.setSpmId(spf_milid);
        AoSupervisorFile.setType(psType);
        if (StringUtil.isNotBlank(fbid)) {
            AoSupervisorFile.setPcId(fbid);
        }
        Integer count = 0;
        Map paraMap = new HashMap<>();
        paraMap.put("projectId", AoSupervisorFile.getProjectId());
        if ("055".equals(psType) || "061".equals(psType) || "081".equals(psType)) {
            // 特殊处理：初验： 055 验收报告 终验：061验收报告 验收阶段：081 验收报告 三种文档整体按顺序排列
            List<String> typeList = new ArrayList<String>();
            typeList.add("055");
            typeList.add("061");
            typeList.add("081");
            paraMap.put("typeList", typeList);
        } else if ("036".equals(psType) || "037".equals(psType)) {
            // 特殊处理：
            List<String> typeList = new ArrayList<String>();
            typeList.add("036");
            typeList.add("037");
            paraMap.put("type", AoSupervisorFile.getType());
        } else {
            if (StringUtils.isNotBlank(AoSupervisorFile.getPcId())) {
                paraMap.put("pcId", AoSupervisorFile.getPcId());
            }
            if (StringUtils.isNotBlank(AoSupervisorFile.getSpmId())) {
                paraMap.put("spmId", AoSupervisorFile.getSpmId());
            }
            paraMap.put("type", AoSupervisorFile.getType());
        }
        count = supervisorFileService.selectMaxOrderBySupervisorFile(paraMap) + 1;
        NumberFormat formatter = new DecimalFormat("000");
        String AsOrderNum = formatter.format(count);
        return AsOrderNum;
    }
    /**
     * @param type
     * @param model
     * @Author:zhaoyongke
     * @Description:根据type 获取路径
     * @Date:17:06 2020/12/1
     */
    public String getUrl(String type, Model model) {
        String re_url = "";
        /*咨询单位*/
        BaseCompany company=new BaseCompany();
        company.setBcId("1564895");
        BaseCompany AlstCompany = baseCompanyService.selectOne(company);
        switch (type) {
            case "005":
                // 会议纪要
                model.addAttribute("wjNum", "21");
                re_url = "/jc/projectManager/schy-hyjy-form";
                break;
            case "007":
                // 项目经理任命书
                model.addAttribute("wjNum", "11");
                re_url = "/jc/projectManager/kgzb_rms-form";
                break;
            case "026":
                // 交付记录单
                model.addAttribute("wjNum", "11");
                re_url = "/jc/projectManager/jfjl-form";
                break;
            case "027":
                // 完工证明
                model.addAttribute("wjNum", "11");
                re_url = "/jc/projectManager/wgzm-form";
                break;
            case "028":
                // 检测周报
                model.addAttribute("wjNum", "11");
                re_url = "/jc/projectManager/qt_jczb-form";
                break;
            case "029":
                // 其他 会议纪要
                model.addAttribute("wjNum", "11");
                re_url = "/jc/projectManager/qt_xmhy-form";
                break;
            case "031":
                // 检测款支付
                model.addAttribute("wjNum", "11");
                re_url = "/jc/projectManager/qt_jckzf-form";
                break;
            case "037":
                // 其他 检测日志
                model.addAttribute("wjNum", "11");
                re_url = "/jc/projectManager/qt_jcrz-form";
                break;
            case "038":
                // 其他 检测月报
                model.addAttribute("wjNum", "21");
                re_url = "/jc/projectManager/qt_jcyb-form";
                break;
            default:

        }
        return re_url;
    }
    /**
     * @param model
     * @param type
     * @param spf_prjid
     * @param fbCode
     * @param supervisorProjectdto
     * @param orderCode
     * @Description:特殊处理
     * @Author:Zhangshuo
     * @Date:11:19 2020-12-19
     */
    private void doSomeSpecialSthing(Model model, String type, String spf_prjid, String fbCode, JcProjectDTO supervisorProjectdto, String orderCode) {

        ProjectUnitConstructionDTO unitConstructiondto = new ProjectUnitConstructionDTO();
        unitConstructiondto.setSupervisorProjectId(spf_prjid);
        if ("039".equals(type)) {
            /*材料进场检验报告*/
            unitConstructiondto.setConstructionSubContractNumber(fbCode);
        }

        if (com.qili.core.shiro.Principal.hasRole("nupm")) {
            //承建单位
            unitConstructiondto.setProjectManager(CommonUtil.getUserId());
        }
        if ("111".equals(type)) {
            /*监理通知回执单 需要查询监理通知选择的承建单位*/
            String fileId = supervisorProjectdto.getFileId();
            SupervisorFile fileparent = supervisorFileService.selectByPrimaryKey(fileId);
            String linkId = fileparent.getLinkId() + "";
            if (StringUtil.isNotBlank(linkId)) {
                SupervisorProjectForms form = supervisorProjectFormsService.selectByPrimaryKey(linkId);
                /*承建单位项目经理*/
                String cjManagerUserId = form.getSpfF30() + "";
                if (StringUtil.isNotBlank(cjManagerUserId)) {
                    unitConstructiondto.setProjectManager(cjManagerUserId);
                }
                String parentordercode = "JLTZ-" + form.getOrderCode();
                model.addAttribute("parentordercode", parentordercode);
            }


        }
        List<ProjectUnitConstructionDTO> listcjlist = projectUnitConstructionService.selectProjectUnitList(unitConstructiondto);
        //承建单位名称
        ArrayList<String> AlstCjdwstr = new ArrayList<>();
        //承建合同名称
        ArrayList<String> AlstCjHtstr = new ArrayList<>();
        for (int i = 0; i < listcjlist.size(); i++) {
            AlstCjdwstr.add(listcjlist.get(i).getUnitConstruction());
            // 承建合同名称
            AlstCjHtstr.add(listcjlist.get(i).getConstructionContract());
        }
        String cj = AlstCjdwstr.toString();
        String cjstr = "";
        if (StringUtil.isNotBlank(cj)) {
            //截取前后【】
            cjstr = cj.replaceAll("\\[", "").replaceAll("\\]", "");
        }
        String cjht = AlstCjHtstr.toString();
        String cjhtstr = "";
        if (StringUtil.isNotBlank(cjht)) {
            //截取前后【】
            cjhtstr = cjht.replaceAll("\\[", "").replaceAll("\\]", "");
        }
        model.addAttribute("cj", cjstr);
        model.addAttribute("cjht", cjhtstr);
        if ("080".equals(type) || "060".equals(type) || "054".equals(type)) {
            // 监理 工作总结报告  查询统计文档列表
            getFileTypeCountList(model, spf_prjid);
            //获取项目分包及建设内容
            getProjectUnitInfor(model, supervisorProjectdto, listcjlist);
        }
        if (type.equals("039")) {
            /*材料设备进场检验报告*/
            orderCode = "-" + fbCode + "-" + orderCode;
        } else if (type.equals("040") || type.equals("041")) {
            /*设备开箱检验报告 设备加电检测记录表*/
            //获取材料进场检验报告的序号
            String fileId = supervisorProjectdto.getFileId();
            SupervisorFile file = supervisorFileService.selectByPrimaryKey(fileId);
            String lnkid = file.getLinkId();
            SupervisorProjectForms from = supervisorProjectFormsService.selectByPrimaryKey(lnkid);
            orderCode = from.getOrderCode();
        }
        // 文件类型编号
        model.addAttribute("orderCode", orderCode);
        model.addAttribute("listcjlist", listcjlist);
    }
    /**
     * @param model
     * @param supervisorProjectdto
     * @param listcjlist
     * @Description:
     * @Author:Zhangshuo
     * @Date:11:22 2020-12-19
     */
    private void getProjectUnitInfor(Model model, JcProjectDTO supervisorProjectdto, List<ProjectUnitConstructionDTO> listcjlist) {
        StringBuilder AsbFbText = new StringBuilder();
        AsbFbText.append(supervisorProjectdto.getProjectName() + "（项目名称）");
        AsbFbText.append("包含 " + (listcjlist.size()) + "个子项目，分别是");
        StringBuilder AsbItems = new StringBuilder();
        StringBuffer pjText = new StringBuffer();
        int y = 1;
        for (int i = 0; i < listcjlist.size(); i++) {
            ProjectUnitConstruction AoTmp = listcjlist.get(i);
            AsbFbText.append("《" + AoTmp.getConstructionContract() + "》（包号为" + AoTmp.getConstructionSubContractNumber() + "）、");
            AsbItems.append("《" + AoTmp.getConstructionContract() + "》合同（合同编号为" + AoTmp.getContractNo() + "）由" + AoTmp.getUnitConstruction() + "（承建单位）承担，主要建设内容包括***等。");
            pjText.append("" + (i + 1) + "、《" + AoTmp.getConstructionContract() + "（" + (i + 1) + "子项目名称）》合同（合同编号为" + AoTmp.getContractNo() + "）于****年**月**日完成到货验收，于****年**月**日完成三方检查检验，于****年**月**日完成项目初验。");
            y++;
        }
        AsbFbText.append(AsbItems.toString());
        model.addAttribute("prjcontent", AsbFbText.toString());
        model.addAttribute("pjtext", pjText.append("" + y + "、系统资料齐全,能够满足项目管理和维护需要。" + (y + 1) + "、在监理工作的基础上和经过多次对建设内容的核对，监理方经过研究认为" + supervisorProjectdto.getProjectName() + "可以进行验收"));

        /*1、《***（1子项目名称）》合同（合同编号为***）于****年**月**日完成到货验收，于****年**月**日完成三方检查检验，于****年**月**日完成项目初验。
        2、《***（2子项目名称）》合同（合同编号为***）于****年**月**日完成到货验收，于****年**月**日完成三方检查检验，于****年**月**日完成项目初验。
        3、系统资料齐全,能够满足项目管理和维护需要。4、在监理工作的基础上和经过多次对建设内容的核对，监理方经过研究认为该******可以进行验收。*/
        //**项目（项目名称）包含 **个子项目，
        //分别是
        //《***（1 子项目名称）》（包号）、
        //《***（2 子项目名称）》（包号）。
        //
        //
        //《***（1 子项目名称）》合同（合同编号为 ***）由 **（承建单位）承担，主要建设内容包括 ***等。
        //《***（2 子项目名称）》合同（合同编号为 ***）由 **（承建单位）承担，主要建设内容包括 ***等。
    }
    /**
     * @param model
     * @param spf_prjid
     * @Description:
     * @Author:Zhangshuo
     * @Date:11:22 2020-12-19
     */
    private void getFileTypeCountList(Model model, String spf_prjid) {
        SupervisorFileDTO filedto = new SupervisorFileDTO();
        filedto.setProjectId(spf_prjid);
        List<SupervisorFileDTO> wjList = supervisorFileService.getFileCountByType(filedto);
        model.addAttribute("wjList", wjList);//
        Integer count = 0;
        for (int i = 0; i < wjList.size(); i++) {
            count = count + wjList.get(i).getCount();
        }
        model.addAttribute("count", count);//
    }
    /**
     * @param model
     * @param type
     * @param fileId
     * @Author:Zhangshuo
     * @Description:解析Word文件到List
     * @Date:14:04 2020-12-10
     */
    private void parsingFileDataToList(Model model, String type, String fileId, String pPrjId, String pPkgId) throws Exception {
        switch (type) {
            case "039"://材料检验
                //获取合同比对报告文件地址
                SupervisorFile supervisorFile = new SupervisorFile();
                supervisorFile.setProjectId(pPrjId);
                supervisorFile.setPcId(pPkgId);
                supervisorFile.setType("044");
                int AiCnt = supervisorFileService.selectCount(supervisorFile);
                if (AiCnt == 1) {
                    supervisorFile = supervisorFileService.selectOne(supervisorFile);
                    String AsSaveContactPath = supervisorFile.getUrl();
                    List<List<String>> AlstWordData = WordUtil.getWordTableData(AsSaveContactPath, 1, 6);
                    model.addAttribute("htlist", AlstWordData);
                    model.addAttribute("htlistJson", JSONArray.toJSONString(AlstWordData));
                } else if (AiCnt == 0) {
                    throw new Exception("非常抱歉，项目ID:" + pPrjId + "的项目未发现合同比对报告，无法进行合同比对。");
                } else if (AiCnt > 1) {
                    throw new Exception("非常抱歉，项目ID:" + pPrjId + "的项目发现多个合同比对报告，仅支持一个合同进行比对，请删除对于的合同对比报告。");
                }
                break;
            case "040"://开箱检验
            case "041"://加电检测
                // 查询文件
                SupervisorFile file = new SupervisorFile();
                file.setId(fileId);
                file = supervisorFileService.selectByPrimaryKey(file);
                String AsFilePath = file.getUrl();
                List<List<String>> AlstFileTableData = null;
                if (StringUtil.isNotBlank(AsFilePath)) {
                    //读取word中表格数据
                    AlstFileTableData = WordUtil.getWordTableData(file.getUrl(), 1, 6);
                }
                model.addAttribute("devlist", AlstFileTableData);
                break;
        }
    }
    /**
     * @param model
     * @param request
     * @Author:zhaoyongke
     * @Description: 获取阶段里程状态
     * @Date:14:52 2020/12/30
     */
    @RequestMapping(value = "/getLcJdStatus", method = RequestMethod.GET)
    @ResponseBody
    public JsonUtil getLcJdStatus(Model model, HttpServletRequest request) {
        JsonUtil re = new JsonUtil();
        JSONObject jsonObject = new JSONObject();
        String lcId = request.getParameter("lcId");
        String jdId = request.getParameter("jdId");
        JcProjectMilepost milepost = jcProjectMilepostService.selectByPrimaryKey(lcId);
        String lcfinsihstatus = milepost.getFinishStatus();
        JcProjectStage stage = jcProjectStageService.selectByPrimaryKey(jdId);
        String jdfinsihstatus = stage.getFinishStatus();
        jsonObject.put("lc_status", lcfinsihstatus);
        jsonObject.put("jd_status", jdfinsihstatus);
        re.setFlag(true);
        re.setData(jsonObject);
        return re;
    }
}
